<?php

namespace app\admin\model;

use think\Model;

class SysConfig extends Model
{

    private static $instance = null;

    protected $name;

    /*    public function __construct()
        {
            $this->name = 'sys_config_'.date('Ym',time());
        }*/

    public static function getInstance()
    {
        //检测当前类属性$instance是否已经保存了当前类的实例
        if (self::$instance == null) {
            //如果没有,则创建当前类的实例
            self::$instance = new self();
        }
        //如果已经有了当前类实例,就直接返回,不要重复创建类实例
        return self::$instance;
    }

    public function getAll()
    {
        return $this->where(array('status' => 1))->select();
    }

    public function getNames($coin_id)
    {
        return $this->field('name')->where(array('id' => $coin_id))->find();
    }

    public function getOne($where, $field = '*')
    {
        return $this->field($field)->where($where)->find();
    }

    public function getValues($where, $field = 'value')
    {
        return $this->where($where)->value($field);
    }

    public function getList($num = 15)
    {
        $productList = $this->field('*')->order('id', 'DESC')->paginate($num, false, ['query' => request()->param()]);
        if ($productList) {
            $page = $productList->render();// 获取分页显示
            return ['data' => $productList, 'msg' => '数据查询成功', 'page' => $page];
        } else {
            return ['data' => '', 'msg' => '暂无数据', 'page' => ''];
        }
    }

    public function delConfig($id)
    {
        return $this->where(array('id' => $id))->delete();
    }

    public function updateDatas($where, $data)
    {
        return $this->where($where)->update($data);
    }

}
